<?php
include_once( 'config.php' );
if(isset($_POST['submit']))
{
	$username=$user = $_POST['username'];
	$pwd = md5(md5($_POST['password']));
	$forward = $_POST['forward'];
	$userdata = $db->get_one("SELECT * FROM member WHERE `username`='{$user}' and `password`='{$pwd}' limit 0,1");
	if($userdata)
	{
		$randp = get_randp($user); 
		//如果是绑定通兑宝用户 然后推送到通兑宝登录
		if($randp)
		{
			$username1 = soap_client($type='Encrypt',$username);   //用户名加密
			$requesturl=WTOTD_URL.'Interface/PLogin.aspx?zxxyyhmu='.$username1.'&zxxyyhmrp='.$randp.'&zxxyyhmauthorization='.WTOTD_SECRET.'&zxxyyhmrurl='.$forward;
			dheader($requesturl);
		}
		else
		{
			$_SESSION["username"] = $user['username'];	
		}
		
	}
	else
	{
		echo '账户或密码错误';	
	}
}
//获取产品信息
$sql = 'select * from product order by id desc';
$products = $db->select($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>通兑宝PHP+js SDK V1版 Demo - Powered by Old Sea</title>
</head>

<body style="margin:100px auto; width:600px;">
	<?php if($_SESSION["username"]){?>
    	当前登录名 <?php echo $_SESSION["username"];?> <a href="<?php echo WTOTD_URL.'ShopCar.aspx';?>" target="_blank">我的购物车</a> <a href="logout.php">退出</a>
        <?php 
			foreach ($products as $k=>$v)
			{
		?>
        <div style="padding-top:15px; line-height:24px;"><?php echo $v['Pname'];?><br /><a href="<?php echo get_buy($v);?>" <?php if($_SESSION["username"]==$v['UserName']){?> onclick="return checkbuy();"<?php }?>  target="_blank">购买</a></div>
    <?php
			}}else{
	?>
	<!-- 普通登录 -->
    <table width="290" cellpadding="3" cellspacing="3">
<form method="post" action="login.php" onsubmit="return check();">
<input name="forward" type="hidden" id="forward" value="<?php echo HTTP_REFERER;?>">
<tr>
<td colspan="2" class="f_gray">您尚未登录...</td>
</tr>
<tr >
<td width="77" align="right">用户名：</td>
<td width="177"><input name="username" type="text" id="username"  style="width:140px"></td>
</tr>
<tr >
<td align="right">密 码：</td>
<td><input name="password" type="password" id="password" style="width:140px;" >
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value=" 登 录 ">&nbsp;&nbsp;<br /></td>
</tr></form>
</table>
	<!-- js登录 -->
<p><img src="js/wtotd_login.png" title="点击进入授权页面" alt="点击进入授权页面" border="0" onclick="testMessageBox();"/></p>
    <?php }?>
</body>
</html>
<script type="text/javascript" src="js/jquery-1.7.1.min.js?<?php echo time();?>"></script>
<script type="text/javascript" src="js/config.js?<?php echo time();?>"></script>
<script type="text/javascript" src="https://www.wtotd.com/scripts/JSLogonPhp.js?<?php echo time();?>"></script>
<script>
	function check()
	{
		var u = $('#username').val();
		var p = $('#username').val();
		if(u=='')
		{
			alert('请输入用户名');
			
			return false;	
		}
		if(p=='')
		{
			alert('请输入密码');
			
			return false;	
		}
		return true;	
	}
	function checkbuy()
	{
		alert('不能购买自己的产品');
		return false;	
	}
</script>
